package com.baizhi.controller;


import com.baizhi.entity.Fruit;
import com.baizhi.service.FruitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 2017class
 * @since 2021-11-26
 */
@RestController
@CrossOrigin
@RequestMapping("/fruit")
public class FruitController {
    @Autowired
    private FruitService fruitService;

    @RequestMapping("queryAll")
    public List<Fruit> queryAll(){
        return fruitService.list(null);
    }

    @DeleteMapping("{id}")
    public void delete(@PathVariable Long id){
        System.out.println(id);
        fruitService.removeById(id);
    }

    @PostMapping
    public void add(@RequestBody Fruit fruit){
        fruitService.save(fruit);
    }

    @GetMapping("{id}")
        public Fruit selectOne(@PathVariable Long id){
        Fruit byId = fruitService.getById(id);
        return byId;
    }

    @PutMapping
    public void updateFruit(@RequestBody Fruit fruit){
        fruitService.updateById(fruit);
    }
}

